package com.gin.supermarket_inventory_system.inventory.dto.vo;

import com.gin.database.base.BaseVo;
import com.gin.supermarket_inventory_system.inventory.entity.InventoryReceiptDetailPo;
import com.gin.supermarket_inventory_system.inventory.enums.InventoryReceiptType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @since : 2023/10/12 17:00
 * @author : ginstone
 * @version : v1.0.0
 **/
@Getter
@Setter
@Schema(description = "视图对象:库存数量变动详情")
public class InventoryReceiptDetailVo extends BaseVo {
    @Schema(description = "单据类型")
    InventoryReceiptType type;

    @Schema(description = "单据ID")
    long receiptId;

    @Schema(description = "库存id")
    long inventoryId;

    @Schema(description = "数量或变动数量")
    int amount;

    @Schema(description = "单价")
    double price;

    @Schema(description = "总价")
    double totalPrice;

    @Schema(description = "备注")
    String remark;

    @Schema(description = "全名(填充, 商品名+库存名)")
    String name;

    @Schema(description = "规格(填充)")
    String spec;

    @Schema(description = "条码(填充)")
    String barcode;

    public InventoryReceiptDetailVo(InventoryReceiptDetailPo po) {
        // 复制Po的字段
        BeanUtils.copyProperties(po, this);
    }

    /**
     * 将持久对象列表转换为视图对象列表
     * @param data 持久对象列表
     * @return 视图对象列表
     */
    public static List<InventoryReceiptDetailVo> toVoList(List<InventoryReceiptDetailPo> data) {
        if (data == null) {
            return new ArrayList<>();
        }
        return data.stream().map(InventoryReceiptDetailVo::new).toList();
    }
}
